<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%
boolean rental = false;
if (request.getAttribute("rental") != null) {
	rental = ((Boolean) request.getAttribute("rental")).booleanValue();
}
%>

<table>
	<tr>
		<td>Street Address:<form:input path="property.streetAddress" size="90"/>
	</tr>
	<tr>
		<td>Suburb:
		<form:select path="property.suburb.id">
			<form:option value="Not Selected" id="" />
			<form:options items="${suburbs}" itemValue="id" itemLabel="name" />
		</form:select>
		</td>
	</tr>
	<tr>
		<td>Price From:
		<form:input path="property.priceFrom" />
		Status:<form:select path="property.status">
			<form:option value="Not Selected" id="" />
			<form:options items="${statuses}" />
		</form:select>
		</td>
	</tr>
	<%if (!rental) {%>	
	<tr>
		<td>Price To:<form:input path="property.priceTo"/>Price Changed:<form:checkbox path="property.priceChanged" value="true" />Ignore Price Changed:<form:checkbox path="property.ignorePriceChanged" value="true" /></td>
	</tr>
	<% } %>
	<tr>
		<td>Bedrooms:<form:input path="property.numberBedrooms"/></td>
	</tr>
	<tr>
		<td>Bathrooms:<form:input path="property.numberBathrooms"/></td>
	</tr>
	<tr>
		<td>Car Spaces:<form:input path="property.numberCarSpaces"/></td>
	</tr>
	<tr>
		<td>Rent:<form:input path="property.rent"/><%if (!rental) {%>Tennanted:<form:checkbox path="property.currentlyTenanted" value="true" /><%} else {%>Fully Furnished:<form:checkbox path="property.fullyFurnished" value="true" />Partly Furnished:<form:checkbox path="property.partlyFurnished" value="true" /><% } %></td>
	</tr>	
	<tr>
		<td>URL:<form:input path="property.url" size="90"/></td>
	</tr>
	<tr>
		<td>Image:<form:input path="property.imageUrl" size="90"/></td>
	</tr>
	<tr>
		<td>Map:<form:input path="property.map" size="90"/></td>
	</tr>
	<tr>
		<td>Description:<form:textarea path="property.description" cols="55" rows="10" /></td>
	</tr>
	<tr>
		<td>Comments:<form:textarea path="property.comments" cols="55" rows="10" /></td>
	</tr>
	<tr>
		<td><input type="button" value="Submit" onclick="validate()" />
	</tr>
</table>

<script>
function validate() {
	if (document.forms[0].elements["property.streetAddress"].value == '') {
		alert("Please enter an address!")
	}
	else if (document.forms[0].elements["property.suburb.id"].selectedIndex <= 0) {
		alert("Please select a suburb!")
	}
	<%if (!rental) {%>
	else if (document.forms[0].elements["property.priceFrom"].value == '') {
		alert("Please enter a price!")
	}
	<% } %>
	else if (document.forms[0].elements["property.numberBedrooms"].value == '') {
		alert("Please enter number bedrooms!")
	}
	else if (document.forms[0].elements["property.numberBathrooms"].value == '') {
		alert("Please enter number bathrooms!")
	} 
	else {
		document.forms[0].submit()
	}
}
</script>